package com.amado.course37CharStream;

import java.io.*;
/**
 * 字节流转换为字符流
 * @author Administrator
 *
 */
public class S04OutputStreamWriterTest {
	public static void main(String[] args) throws IOException {
		String file = "D:\\test3.txt";
		String charset = "UTF-8";
		// 写字符换转成字节流
		FileOutputStream outputStream = new FileOutputStream(file);
		FileInputStream inputStream = new FileInputStream(file);
		Writer writer = new OutputStreamWriter(outputStream, charset);
		try {
			writer.write("come 北京");
		} finally {
			writer.close();
		} // 读取字节转换成字符
		Reader reader = new InputStreamReader(inputStream, charset);
		StringBuffer buffer = new StringBuffer();
		char[] buf = new char[64];
		int count = 0;
		try {
			while ((count = reader.read(buf)) != -1) {
				buffer.append(buf, 0, count);
			}
		} finally {
			reader.close();
		}
		System.out.println(buffer);
	}
}
